<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<%@include file="/WEB-INF/base.jspf"%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>百家乐管理</title>
<style type="text/css">
	.p-c-flexwrapper {
		display:flex;
		align-items:center;
		margin-right:16px;
		margin-bottom:16px;
	}
	.p-c-flexwrapper > span {
		text-align: right;
	}
		.modal-dialog {
		max-width: 1000px;
	}
	.p-c-flexwrapper > .form-control {
		width:100px;
	}
table th,table tr,table td {
text-align: center;
vertical-align:middle;
}
.hidden-td {
	display:none;
}

.butt-xiangqing {
    color: #fff;
    background-color: #009688;
    border-color: #009688;
    display: inline-block;
    padding: 6px 12px;
    margin-bottom: 0;
    font-size: 14px;
    font-weight: 400;
    line-height: 1.42857143;
    text-align: center;
    white-space: nowrap;
    vertical-align: middle;
    user-select: none;
    background-image: none;
    border: 1px solid transparent;
    border-radius: 4px;
}

.modal-body > p {
       display: flex;
    /* align-items: center; */
    margin-right: 16px;
    margin-bottom: 16px;
    max-width: 950px;
    display: -webkit-flex;
   /*  justify-content: space-between;  */
    flex-direction: row;
    width: 100%;
    flex-wrap: wrap; 
}

.modal-body > p > span {
    margin: 0 10px;
    padding: 5px 0;
}
#button-i-savePeiLv{
	margin-left:50px !important;
}
.modal-body > p > .form-control {
    color: #000;
    font-size: 16px;
    font-weight: 500;
}

.modal-body {
    display: flex;
    flex-wrap: wrap;
}

.backbet,.backCor {
    color: red !important;
}

.peilv{
	display: block;
	overflow: hidden;
}
.peilv .peilv-left{
	float: left;
	width:80px;
	margin-top: 27px;
	margin-left: 10px;
}

.peilv .peilv-right{
	float: left;
	width: 600px;
}

.peilv .peilv-right-btn{
	position: absolute;
	right: 0;
	bottom: 20px;
}

.peilv .peilv-right .form-control{
	display: inline;
	width:auto;
}
.peilv-right ul li{
	overflow: hidden;
	margin: 20px 0;
}

.peilv-right ul li div{
	float: left;
	width:33.333%;
	text-align: right;
}

.peilv-right ul li div:first-child{
	width:25%;
}

.peilv-right ul li div span{
	width:80px;
	
}

.peilv-right ul li div .form-control{
	width:80px !important;
}

#DetailAndEditModal .modal-body p{
	float: left;
	width:45%;
} 

#DetailAndEditModal .modal-body p .form-control{
	width:60%;
}

#DetailAndEditModal .modal-body p span{
	width: 80px;
    text-align: right;
}
</style>
</head>
<body>
<div style="overflow：hidden" >
<div style="width:60%; float:left;overflow：hidden">
	<ul>
		<li style="float:left;" class="li-time"><input style="margin-right:10px;height:38px;"  type="text" name=""  value="" id="obj-date1" placeholder="开始时间" /></li>
		<li style="float:left; margin-right:20px;"><input type="text" name="" style="height:38px;" id="obj-huiyhuanzh" value="" placeholder="用户查询" /></li>
		<li><button type="button" class="layui-btn layui-btn-radius" id="btn-searche-find">查询</button><button type="button" class="layui-btn layui-btn-radius" id="btn-research">重置</button></li>
	</ul>
	<ul>
		<li style="float:left;"><input style="margin-right:10px;height:38px;" type="text" name="" id="obj-date2" placeholder="结束时间" /></li>
		<li style="float:left; margin-right:20px;"><input type="text" name="" style="height:38px;" id="obj-daili" value="" placeholder="开奖期号" /></li>
		<li style="float:left; margin-right:20px;">
			<select style="height:38px;">
				<option value=''>全部</option>
				<option value='1'>已开奖</option>
				<option value='0'>未开奖</option>
			</select>
		</li>
	</ul> 
</div>
<div style=" float:right; margin-right:10px;margin-top:10px;"><button  class="save btn btn-primary btn-lg" >百家乐基本设置</button></div>
</div>

	

	
	<table id="table-i-qqAccountList" class="table table-striped table-bordered table-hover" style="margin-top: 20px;">
		<thead>
			<tr>
				<th style="display:none;"></th>
				<th>用户名</th>
				<th>期号</th>
				<th>庄</th>
				<th>闲</th>
				<th>庄对</th>
				<th>闲对</th>
				<th>和</th>
				<th>大</th>
				<th>小</th>
				<th>完美对子</th>
				<th>任意对子</th>
				<th>下注总额</th>
				<th>中奖金额</th>
				<th>下注时间</th>
				<th>桌号</th>
				<th>状态</th>
				<th>详情</th>
				<th>删除</th>
			</tr>
		</thead>
		<tbody>
		</tbody>
	</table>
	<div>
		<div class="modal fade" id="addAndEditModal" tabindex="-1" role="dialog" aria-labelledby="addAndEditModal" aria-hidden="true">
			<div class="modal-dialog" style="width:1000px;">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
						<h4 class="modal-title" id="myModalLabel">新增/修改</h4>
					</div>
					<div class="modal-body">
					<input id="input-i-id" hidden="hidden" class="input-auto" />
						<p class="p-c-flexwrapper" ><span style="width:115px">百分比设置：</span>
		            		<select class="form-control roomId baifenbiSelect">
		            			<option value="1">1号房</option>
		            			<option value="2">2号房</option>
		            			<option value="3">3号房</option>
		            			<option value="4">4号房</option>
		            			<option value="5">5号房</option>
		            			<option value="6">6号房</option>
		            		</select>
							<select class="form-control baifenbi" style="margin:0 16px;">
								<option value="0">关闭</option>
								<option value="1">10%</option>
								<option value="2">20%</option>
								<option value="3">30%</option>
								<option value="4">40%</option>
								<option value="5">50%</option>
								<option value="6">60%</option>
								<option value="7">70%</option>
								<option value="8">80%</option>
								<option value="9">90%</option>
								<option value="10">100%</option>
							</select>
							<button class="btn btn-success" id="button-i-saveBaiFenBi">保存</button>
						</p>
		            	<p class="p-c-flexwrapper">
		            		<span>房间限制金额：</span>
		            		<select class="form-control roomId moneySelect">
		            			<option value="1">1号房</option>
		            			<option value="2">2号房</option>
		            			<option value="3">3号房</option>
		            			<option value="4">4号房</option>
		            			<option value="5">5号房</option>
		            			<option value="6">6号房</option>
		            		</select>
		            		<span style="width:90px;display:inline-block;margin-left:16px;">最大金额：</span>
		            		<input type="number" class="form-control max-money">
		            		<span style="width:90px;display:inline-block;margin-left:16px;">最小金额：</span>
		            		<input type="number" class="form-control min-money" style="margin-right:16px;">
		            		<button class="btn btn-success" id="button-i-saveMoney">保存</button>	            		
		            	</p>
		            	<div class="p-c-flexwrapper peilv" style="margin-top:-10px;position:relative;width: 750px;">
		            		<div class="peilv-left">修改赔率：</div>
		            		<div class="peilv-right">
			            		<ul>
				            		<li>
				            			<div>
				            				<span >庄：</span>
					            			<input data-rebate="1" type="number" class="form-control zhuang">
				            			</div>
				            			<div>
				            				<span >闲：</span>
					            		<input data-rebate="2" type="number" class="form-control xian">	
				            			</div>
				            			<div>
				            				<span >和：</span>
					            		<input data-rebate="5"  type="number" class="form-control he">
				            			</div>
				            		</li>
				            		<li>
				            			<div>
				            				<span >庄对：</span>
					            			<input data-rebate="4"  type="number" class="form-control zhuangdui">
				            			</div>
				            			<div>
				            				<span >闲对：</span>
					            			<input data-rebate="3"  type="number" class="form-control xiandui">	
				            			</div>
				            			<div>
				            				<span>大：</span>
					            			<input data-rebate="6"  type="number" class="form-control xiandui" >
				            			</div>
				            		</li>
				            		<li>
				            			<div>
				            				<span>小：</span>
					            			<input data-rebate="7"  type="number" class="form-control xiandui">
				            			</div>
				            			<div>
				            				<span>完美对子：</span>
					            			<input data-rebate="8"  type="number" class="form-control xiandui">	
				            			</div>
				            			<div>
				            				<span>任意对子：</span>
					            			<input data-rebate="9"  type="number" class="form-control xiandui">
					            			
				            			</div>
				            		</li>
			            		</ul>
		            		</div>
		            		<div class="peilv-right-btn"><button class="btn btn-success" id="button-i-savePeiLv">保存</button>	</div>
		            	</div>
		            	<p class="p-c-flexwrapper">
		            		<span>8遇到9返点率：</span>
		            		<span style="width:60px;margin-left:17px;">返点率:</span>
		            		<input type="number" class="form-control fandian" style="width:80px;">
		            		<button class="btn btn-success" style="margin-left:16px;" id="button-i-famdian">保存</button>	   
		            	</p>
					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
					</div>
				</div>
			</div>
		</div>
	</div>
	
<!-- 模态框（Modal） -->
<div class="modal fade" id="deleteModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
            </div>
            <div class="modal-body">你确定要删除该条记录吗？</div>
            <div class="modal-footer">
                <button type="button" class="btn btn-danger" id="btn-i-delModalBtn">删除</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div>	
	
<div class="modal fade" id="noticeModal" tabindex="-1" role="dialog" aria-labelledby="noticeModal" aria-hidden="true">
    <div class="modal-dialog class-fake-alert">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            </div>
            <div class="modal-body" ></div>
            <div class="modal-footer">	      
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>   	

<div class="modal fade" id="DetailAndEditModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog" style="width:600px!important;">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
            </div>
            <div class="modal-body"></div>
            <div class="modal-footer" style="text-align: center;">
                <button type="button" class="btn btn-default btn-lg" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>
</div>


	
	<script type="text/javascript" src="/js/zhengzeTools.js"></script>
	<script type="text/javascript">
	
		layui.use('laydate', function() {
			var laydate = layui.laydate;
			laydate.render({
				elem : '#obj-date1' 
			});
			laydate.render({
				elem : '#obj-date2' 
			});
		});
	var state="";
	$("#button-i-famdian").on("click",function(){
		$.ajax({
			  url: "/bjlhtgl/percent.do",
			  type: "post",
			  data: {percent1: $(".fandian").val()},
			  dataType: "json",
			  success:function(data){
				  showNoticeModal("修改成功！")
			  },
			});	
	})
	 function DataTable01(){
			var oTable=	$("#table-i-qqAccountList").DataTable({
					 "bProcessing" : false, // 是否显示取数据时的那个等待提示
					"bServerSide" : true,//这个用来指明是通过服务端来取数据
					 "bPaginate" : true, //是否显示分页 
					"sAjaxSource" : "/bjlhtgl/findUserbettingRecord.do",//这个是请求的地址
					"fnServerData" : retrieveData, // 获取数据的处理函数
					"destroy":true,
				      // "bPaginate": true,
				       "bLengthChange": true,      
				      "bSort": false,
				      // "bInfo": true,
				      "bAutoWidth": false,
//				         "bServerSide":true,
				      'aLengthMenu':[5,10, 20], 
				       "searching": false,  
				       "pagingType": "simple_numbers",
				       "dom": "t<'tableinfo'i<'tableSearch'p>l>", 
				       
				       "language": {//语言设置  
				            "lengthMenu": "每页显示 _MENU_ 条记录",     
				            "zeroRecords": "没有检索到数据",     
				            "sInfo": "当前显示 _START_ 到 _END_ 条，共 _TOTAL_ 条记录",     
				            "info": "没有数据",     
				            "oPaginate": {     
				                "sFirst": "首页",     
				                "sPrevious": "前一页",     
				                "sNext": "后一页",     
				                "sLast": "尾页"    
				          	},
				            "search":"",
				            "searchPlaceholder": "请输入关键字",
				            "infoFiltered":   "(从  _MAX_ 记录中搜索出结果)",
				            "infoEmpty":      "没有找到匹配的信息",
				         },  
				         "columnDefs": [{"defaultContent": "",
                             "targets": "_all"}],
				        "aoColumns": [
				        	{"data": "id", "className": "hidden-td id-edit-td"},
							 {"data": "name", "className": "userid-edit-td"},
		                     {"data": "issueNumber", "className": "qihao-edit-td"},
		                     {"data": "zhuang", "className": "zhuang-edit-td"},
		                     {"data": "xian", "className": "xian-edit-td"},
		                     {"data": "zhuangdui", "className": "zhuangdui-edit-td"},
		                     {"data": "xiandui", "className": "xiandui-edit-td"},
		                     {"data": "he", "className": "he-edit-td"},
		                     {"data": "large", "className": "large-edit-td"},
		                     {"data": "small", "className": "small-edit-td"},
		                     {"data": "perfectPairx", "className": "perfectPairx-edit-td"},
		                     {"data": "arbitraryPairsx", "className": "arbitraryPairsx-edit-td"},
		                     {"data": "totalBet", "className": "he-edit-td"},
		                     {"data": "winningAmount", "className": "he-edit-td"},
		                     {"data": "bettingtime", "className": "bettingtime-edit-td"},
		                     {"data": "tableNumber", "className": "zh-edit-td"},
		                     {"data": "state", "className": "state-edit-td"},
		                     {"data": null, "defaultContent": "<button class='butt-xiangqing'>详情</button>"},
		                     {"data": null, "defaultContent": "<button class='btn btn-danger btn-c-delBankInfo btn-sm'>删除</button>"},
		                 ], 
				})
				
			
				

	function retrieveData(sSource, aoData, fnCallback) {
				$.ajax({
					url : sSource,//这个就是请求地址对应sAjaxSource
					data : {
						"pageCount":aoData[0].value,
						"startIndex":aoData[3].value,
						"lineCount":aoData[4].value,
						"user":$("#obj-huiyhuanzh").val(),
						"time1":$("#obj-date1").val(),
						"time2":$("#obj-date2").val(),
						"period":$("#obj-daili").val(),
						"state":state,
						"id":"",
					},//这个是把datatable的一些基本数据传给后台,比如起始位置,每页显示的行数
					type : 'post',
					dataType : 'json',
					async : false,
					success : function(result) { 
						 var newData = result.aaData
						 console.log(newData,'newData的值')
		        		for (var i = 0; i < newData.length; i++) {
		        			var item = newData[i]
		        			if (item.state == 1) {
		        				item.state = '已开奖'
		        			} else if(item.state==0) {
		        				item.state = "未开奖"
		        			}else if(item.state==2){
		        				item.state = "已退款"
		        			}
		        		}
						result.aaData = newData;
						fnCallback(result);//把返回的数据传给这个方法就可以了,datatable会自动绑定数据的
					},
					error : function(msg) {
					}
				});
			}
		}
			    
			DataTable01() 
	
	   		$(".save.btn-lg").on("click", function(e) {
				$.ajax({
					  url: "/bjlhtgl/tableNumerAttributeSetup.do",
					  type: "post",
					  data: {tableNumber: "1"},
					  dataType: "json",
					  success:function(data){
						$(".fandian").val(String(data.data.percent))
					  	$("select.roomId").val("1")
					  	$(".baifenbi").val(String(data.data.percentage))
					  	$(".max-money").val(String(data.data.maximumAmount))
					  	$(".min-money").val(String(data.data.minimumSum))
	  					$.ajax({
						  url: "/bjlhtgl/findBaccaratRatio.do",
						  type: "post",
						  data: {},
						  dataType: "json",
						  success:function(data2){
						  		$("[data-rebate]").each(function(index, element) {
						  			var index = element.dataset.rebate
						  			element.value = data2.data["rebate" + index]
						  		})
				   			$("#addAndEditModal").modal("show")
						  },
						});	
					  },
					});	
	   		}) 
	   		
	   		$("#btn-searche-find").on("click",function(event){
	   			state=$("#obj-daili").parent().next().find("option:selected").text()
	   			if(state=="已开奖"){
	   				state=1;
	   			}else if(state=="未开奖"){
	   				state=0;
	   			}else if(state=="已退款"){
	   				state=2;
	   			}else{
	   				state="";
	   			}
	   			DataTable01() 
	   		})
	   		$("#btn-research").on("click",function(event){
	   			$("#obj-huiyhuanzh").val("");
				$("#obj-date1").val("");
				$("#obj-date2").val("");
				$("#obj-daili").val("");
				state="";
				DataTable01()
	   		})
	   		
	   		$(".baifenbiSelect").on("change", function(e) {
	   			var roomId = $(e.currentTarget).val()
				$.ajax({
					  url: "/bjlhtgl/tableNumerAttributeSetup.do",
					  type: "post",
					  data: {tableNumber: roomId},
					  dataType: "json",
					  success:function(data){
					  	$(".baifenbi").val(String(data.data.percentage))
					  },
					});		   			
	   		})
	   		$(".moneySelect").on("change", function(e) {
	   			var roomId = $(e.currentTarget).val()
	   			$.ajax({
					  url: "/bjlhtgl/tableNumerAttributeSetup.do",
					  type: "post",
					  data: {tableNumber: roomId},
					  dataType: "json",
					  success:function(data){
					  	$(".max-money").val(String(data.data.maximumAmount))
					  	$(".min-money").val(String(data.data.minimumSum))
					  },
					});		   			
	   		})	   		
	   		$("#button-i-saveBaiFenBi").on("click", function(e) {
	   			var id = $(e.currentTarget).closest(".p-c-flexwrapper").find(".baifenbiSelect").val()
	   			var bfbValue = $(e.currentTarget).closest(".p-c-flexwrapper").find(".baifenbi").val() 
	   			//bjlxgbfb
	   			$.ajax({
					  url: "/bjlhtgl/updateBjlControl.do",
					  type: "post",
					  data: {"tableNumber": id, "percentage": bfbValue},
					  dataType: "json",
					  success:function(data){
						  showNoticeModal("操作成功！")
					  },
					});		   			
	   		})
	   		$("#button-i-saveMoney").on("click", function(e) {
	   			var id = $(e.currentTarget).closest(".p-c-flexwrapper").find(".moneySelect").val()
	   			var maxValue = $(e.currentTarget).closest(".p-c-flexwrapper").find(".max-money").val() 
	   			var minValue = $(e.currentTarget).closest(".p-c-flexwrapper").find(".min-money").val() 
	   			$.ajax({
					  url: "/bjlhtgl/updateBjlRoomMoney.do",
					  type: "post",
					  data: {"tableNumber": id, "maximumAmount": maxValue, "minimumSum": minValue},
					  dataType: "json",
					  success:function(data){
						  showNoticeModal("操作成功！")
					  },
					});		   			
	   		})
	   		
	   		/* 下注详情 */
	   		$("#table-i-qqAccountList").on("click",".butt-xiangqing",function(){
	   			var id=$(this).parent().parent().find(".id-edit-td").text();
	   			var that=this;
	   			$("#DetailAndEditModal").modal("show");
	   			$.ajax({
					  url: "/bjlhtgl/findUserbettingRecord.do",
					  type: "post",
					  contentType:"application/x-www-form-urlencoded; charset=utf-8",
					  data: {
						  "pageCount": 1,
						  "startIndex": 0,
						  "lineCount": 5, 
						  "id":id,	
						  "user": "",
						  "time1": "",
						  "time2":"", 
						  "period":"",
						  "state": "",
						  },
					  success:function(data){
						  var newData=data.aaData[0]; 
						  var body = $("#DetailAndEditModal .modal-body");
						  var userName=$(that).parent().parent().find(".userid-edit-td").text()
						  var isuueNumber=$(that).parent().parent().find(".qihao-edit-td").text()
						  var roomId=$(that).parent().parent().find(".zh-edit-td").text()
						  body.empty();
						  body.append("<p><span class='backbet'>用户名：</span><input value='"+userName+"'class='form-control backCor' id='input-i-name' readonly /></p><p><span class='backbet'>期号：</span><input value='"+isuueNumber+"' class='form-control backCor' id='input-i-qihao' readonly />") 
						 if(newData.zhuang=="庄家"){
							 body.append("<p><span>下注玩法：</span><input value='庄' class='form-control' readonly /></p><p><span>下注金额：</span><input value='"+newData.amountOfMoney+"' class='form-control' readonly /></p>")
						 }if(newData.xian=="闲家"){
							 body.append("<p><span>下注玩法：</span><input value='闲' class='form-control' readonly /></p><p><span>下注金额：</span><input value='"+newData.cashDownAmount+"' class='form-control' readonly /></p>") 
						 }if(newData.zhuangdui=="庄对"){
							 body.append("<p><span>下注玩法：</span><input value='庄对' class='form-control' readonly /></p><p><span>下注金额：</span><input value='"+newData.zhuangdusBetOnTheAmount+"' class='form-control' readonly /></p>") 
						 }if(newData.xiandui=="闲对"){
							 body.append("<p><span>下注玩法：</span><input value='闲对' class='form-control' readonly /></p><p><span>下注金额：</span><input value='"+newData.cashPairDownAmount+"' class='form-control' readonly /></p>")  
						 }if(newData.he=="和"){
							 body.append("<p><span>下注玩法：</span><input value='和' class='form-control' readonly /></p><p><span>下注金额：</span><input value='"+newData.andTheAmountOfTheBet+"' class='form-control' readonly /></p>")  
						 }if(newData.large=="大"){
							 body.append("<p><span>下注玩法：</span><input value='大' class='form-control' readonly /></p><p><span>下注金额：</span><input value='"+newData.largeBetAmount+"' class='form-control' readonly /></p>") 
						 }if(newData.small=="小"){
							 body.append("<p><span>下注玩法：</span><input value='小' class='form-control' readonly /></p><p><span>下注金额：</span><input value='"+newData.smallBetAmount+"' class='form-control' readonly /></p>") 
						 }if(newData.arbitraryPairsx=="任意对子"){
							 body.append("<p><span>下注玩法：</span><input value='任意对子' class='form-control' readonly /></p><p><span>下注金额：</span><input value='"+newData.arbitraryPairAmount+"' class='form-control' readonly /></p>")  
						 }if(newData.perfectPairx=="完美对子"){
							 body.append("<p><span>下注玩法：</span><input value='完美对子' class='form-control' readonly /></p><p><span>下注金额：</span><input value='"+newData.perfectPairAmount+"' class='form-control' readonly /></p>") 
						 }  
					  },
					});
	   		})
	   		
			$("#button-i-savePeiLv").on("click", function(e) {
				var request = {
					  url:"/bjlhtgl/upDateOdds.do",
					  type: "post",
					  data: {name: "bjl"},
					  dataType: "json",
					  success:function(data){
						  showNoticeModal("操作成功！")
					  },						
				}
				var allInputs = $(e.currentTarget).closest(".p-c-flexwrapper").find("[data-rebate]")
				for (var i = 0; i < allInputs.length; i++) {
					var element = allInputs[i]
					request.data["rebate" + element.dataset.rebate] = element.value
				}
					
				$.ajax(request)
	   		})	 
			bindDelItemEvent("#table-i-qqAccountList", ".btn-c-delBankInfo","/bjlhtgl/deletexzjl.do")
	</script>
</body>
</html>